﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="../demo.css" rel="stylesheet" type="text/css" />

<script src="../../scripts/boot.js" type="text/javascript"></script>
</head>
<body>
	<h1>理发师数据表格</h1>

	<div style="width: 800px;">
		<div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
			<table style="width: 100%;">
				<tr>
					<td style="width: 100%;"><a class="mini-button"
						iconCls="icon-add" onclick="add()">增加</a> <a class="mini-button"
						iconCls="icon-add" onclick="edit()">编辑</a>
						<a class="mini-button"
						iconCls="icon-remove" onclick="remove()">删除</a>
					</td>
					<td style="white-space: nowrap;"><input id="key"
						class="mini-textbox" emptyText="请输入理发师姓名" style="width: 150px;"
						onenter="onKeyEnter" /> <a class="mini-button" onclick="search()">查询</a>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="datagrid1" class="mini-datagrid"
		style="width: 800px; height: 280px;" allowResize="true"
		url="../../barber" idField="id"
		multiSelect="true">
		<div property="columns">
			<!--id=aa,name=ss-->
			<!--<div type="indexcolumn"></div>        -->
			<div type="checkcolumn"></div>
			<div field="id" width="120" headerAlign="center" allowSort="true">理发师编号</div>
			<div field="username" width="120" headerAlign="center" allowSort="true">理发师姓名</div>
			<!--<div field="password" width="120" headerAlign="center" allowSort="true">理发师密码</div>-->
			<div field="levelname" width="120" headerAlign="center"	allowSort="true">级别</div>
			<div field="sex" width="120" headerAlign="center" allowSort="true" >性别</div>
			<div field="hireTime" width="120" headerAlign="center" allowSort="true">入职时间</div>
			<div field="phone" width="120" headerAlign="center" allowSort="true">电话</div>
		</div>
	</div>


	<script type="text/javascript">
        mini.parse();

        var grid = mini.get("datagrid1");
        console.log(grid)
        grid.load();
        grid.sortBy("createtime", "desc");

        function onaddDaterenderer(e) {
            var value = e.value;
            console.log(value)
            if (value) return mini.formatDate(new Date(value), 'yyyy-MM-dd');
            return "";
        }

        
        function add() {
            
            mini.open({
                url: bootPATH + "../demo/CommonLibs/BarberWindow.html",
                title: "新增理发师", width: 600, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var barber = { action: "insert",};//entity的
                    iframe.contentWindow.SetData(barber);
                    },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        
        function edit() {
            var row = grid.getSelected();
            if (row) {
                row.oldid=row.id
                console.log(row)
                console.log(typeof row)

                mini.open({
                    url: bootPATH + "../demo/CommonLibs/BarberWindow.html",
                    title: "编辑理发师", width: 600, height: 400,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "update", barberdata: JSON.stringify(row) };//标名字Data数据转字符串
                        iframe.contentWindow.SetData(data);

                        // iframe.contentWindow.SaveData(data);

                    },
                    ondestroy: function (action) {
                        grid.reload();

                    }
                });

            } else {
                alert("请选中一条记录");
            }
        }
        function remove() {

            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i<l; i++) {
                        var r = rows[i];
                        console.log(r);
                        ids.push(r.id);
                    }
                    var id = ids.join(',');
                    alert(id)
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "../../barber/delete",
                        data:{
                            ids:id,
                           },
                        success: function (text) {
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            } else {
                alert("请选中一条记录");
            }
        }
        function search() {
            var key = mini.get("key").getValue();
            grid.load({ key: key });
        }
        function onKeyEnter(e) {
            search();
        }
        /////////////////////////////////////////////////
        function onBirthdayRenderer(e) {
            var value = e.value;
            if (value) return mini.formatDate(value, 'yyyy-MM-dd');
            return "";
        }
        function onMarriedRenderer(e) {
            if (e.value == 1) return "是";
            else return "否";
        }
     
        var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];        

        function onGenderRenderer(e) {
            for (var i = 0, l = Genders.length; i < l; i++) {
                var g = Genders[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }



    </script>

	<div class="description">
		<h3>Description</h3>

	</div>
</body>
</html>